﻿@model DatNuocViet.Models.GetWebResourceResult
@{
    ViewBag.Title = "Dat Nuoc Viet";
}
<script type="text/javascript">
    var isFirstLoad = true;
    var isFirstLoad1 = true;
    var target;
    $(document).ready(function () {
        $("#tabs").tabs();
        CKEDITOR.replace('DescriptionVn', { htmlEncodeOutput: true, width: "100%" });
        CKEDITOR.replace('DescriptionEn', { htmlEncodeOutput: true, width: "100%" });
        $("#dialog").dialog({ autoOpen: false, width: 400, height: 100 });
        $("#dialog1").dialog({ autoOpen: false, width: 400, height: 100 });
        $("#dialog2").dialog({ autoOpen: false, width: 550, height: 590 });
        $("#MenuTriAn").removeClass("dropdown").addClass("active");
        LoadImage();
    });
    function InsertImage() {
        if (CKEDITOR.currentInstance) {
            target = CKEDITOR.currentInstance.name;
            $("#dialog").dialog("open");
        }
        else
            alert('Vui lòng chọn văn bản');
    }
    function SubmitUploadImage() {
        var image = '<img alt="loading..." width="24px" height="24px" src="@Url.Content("~/Areas/Admin/Content/Images/loading.gif")" />';
        $("#loading").append(image);
        $("#ImgForm").submit();
    }
    function UploadImage_Complete() {
        if (isFirstLoad == true) {
            isFirstLoad = false;
            return;
        }
        document.getElementById("ImgForm").reset();
        var newImg = $.parseJSON($("#UploadTarget").contents().find("#jsonResult")[0].innerHTML);
        if (newImg.IsValid == false) {
            alert(newImg.Message);
            $("#loading").empty();
            return;
        }
        var imgHtml = CKEDITOR.dom.element.createFromHtml("<img src='" + newImg.ImagePath + "' alt='image'/>");
        if (target == "DescriptionVn") {
            CKEDITOR.instances['DescriptionVn'].insertElement(imgHtml);
        }
        if (target == "DescriptionEn") {
            CKEDITOR.instances['DescriptionEn'].insertElement(imgHtml);
        }
        $("#loading").empty();
        $("#dialog").dialog("close");
    }

    /*hinh anh khach hang*/
    function InsertImage1() {
        $("#dialog1").dialog("open");
    }

    function SubmitUploadImage1() {
        var image = '<img alt="loading..." width="24px" height="24px" src="@Url.Content("~/Areas/Admin/Content/Images/loading.gif")" />';
        $("#loading1").append(image);
        $("#ImgForm1").submit();
    }

    function UploadImage_Complete1() {
        if (isFirstLoad1 == true) {
            isFirstLoad1 = false;
            return;
        }
        document.getElementById("ImgForm1").reset();
        var newImg = $.parseJSON($("#UploadTarget1").contents().find("#jsonResult")[0].innerHTML);
        if (newImg.IsValid == false) {
            alert(newImg.Message);
            $("#loading1").empty();
            return;
        }
        LoadImage();
        $("#loading1").empty();
        $("#dialog1").dialog("close");
    }

    function LoadImage() {
        var Id = 0;
        $.ajax({
            cache: false,
            type: "POST",
            data: "{id:" + Id + "}",
            url: '@Url.Action("GetImages", "AdminTour")',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                $("#imgContainer").empty();
                var stringToBuild = '';
                $.each(result, function (index, images) {
                    stringToBuild += "<div class='tourimage'><img onclick='preTourImage(" + images.Id + ");' onmouseover='this.style.cursor=\"pointer\"' alt='image' src='" + images.Images + "'/></div>"
                });
                $("#imgContainer").append(stringToBuild);
            },
            error: function () {
                alert("Lỗi load image");
            }
        });
    }

    function preTourImage(id) {
        $.ajax({
            cache: false,
            type: "POST",
            data: "{id:" + id + "}",
            url: '@Url.Action("ToursImageDetail", "AdminTour")',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                $("#imageIdEdit").val(result.Id);
                $("#imageEdit").attr("src", result.Images);
                $("#imageSortEdit").val(result.SortOrder);
                $("#imageDelete").removeAttr('checked');
                $("#dialog2").dialog("open");
            },
            error: function () {
                alert("Lỗi lấy thông tin image");
            }
        });
    }

    function TourImageUpdate() {
        var id = $("#imageIdEdit").val();
        var sort = $("#imageSortEdit").val();
        var deleted = $("#imageDelete").attr('checked') == "checked" ? true : false;
        $.ajax({
            cache: false,
            type: "POST",
            data: "{id:" + id + ", deleted:" + deleted + ", sortOrder: " + sort + "}",
            url: '@Url.Action("ToursImagesUpdate", "AdminTour")',
            contentType: "application/json; charset=utf-8",
            dataType: "text",
            success: function (result) {
                alert(result);
                LoadImage();
                $("#dialog2").dialog("close");
            },
            error: function () {
                alert("Lỗi gọi ajax");
            }
        });
    }
    /*end*/
</script>
<div class="contenttitle">
    <div class="titleplace">
        <span>Lời tri ân khách hàng</span>&nbsp;&nbsp;&nbsp;
        @if (ViewBag.message != null)
        {
            <span style="font-weight:600;color:Red;">@ViewBag.message</span>
        }
    </div>
    <div class="clear">&nbsp;</div>
</div>
<div class="contentitem">
    @using (Html.BeginForm("UpdateTriAn", "AdminHome", FormMethod.Post, new { id = "HomeForm", enctype = "multipart/form-data" }))
    {
        <input type="hidden" name="key" value="@Model.Key" />
        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">Trang tiếng việt</a></li>
                <li><a href="#tabs-2">Trang tiếng anh</a></li>
                <li><a href="#tabs-3">Hình ảnh khách hàng</a></li>
            </ul>
            <div id="tabs-1">
                <textarea name="DescriptionVn" id="DescriptionVn" rows="1" cols="1">
                    @Html.Raw(Model.ValueVn)
                </textarea>
            </div>
            <div id="tabs-2">
                <textarea name="DescriptionEn" id="DescriptionEn" rows="1" cols="1">
                    @Html.Raw(Model.ValueEn)
                </textarea>
            </div>
            <div id="tabs-3">
                <input type="button" value="Thêm hình ảnh" onclick="InsertImage1();"/>
                <div id="imgContainer" style="margin-top: 10px;">                
                </div>
                <div class="clear">&nbsp;</div>
            </div>
        </div>
        <p>
            <input type="button" value="Chèn hình ảnh" onclick="InsertImage();"/>
            <input type="submit" value="Lưu" />
        </p>
    }
</div>
<div id="dialog" title="Upload hình ảnh">
     @using (Html.BeginForm("UploadImage", "AdminHome", FormMethod.Post,new{enctype = "multipart/form-data", id="ImgForm",name="ImgForm", target="UploadTarget"}))
     {
        <input type="hidden" name="folderName" id="folderName" value="upload" />
        <input type="file" name="UploadImage" id="UploadImage"/>
        <input type="button" value="Upload" onclick="SubmitUploadImage();" />
        <span id="loading"></span>
        <br />
        <small style="color:Red;">* Hình ảnh nhỏ hơn 1mb - Định dạng file jpg, gif, png</small>
     }
    <iframe id="UploadTarget" name="UploadTarget" onload="UploadImage_Complete();" style="position: absolute;left: -999em; top: -999em;"></iframe>    
</div>
<div id="dialog1" title="Upload hình ảnh">
    @using (Html.BeginForm("UploadImageWidthSave", "AdminHome", FormMethod.Post, new { enctype = "multipart/form-data", id = "ImgForm1", name = "ImgForm1", target = "UploadTarget1" }))
    {
        <input type="hidden" name="folderName1" id="folderName1" value="tour/images" />
        <input type="hidden" value="0" name="Id1" />
        <input type="file" name="UploadImage1" id="UploadImage1" />
        <input type="button" value="Upload" onclick="SubmitUploadImage1();" />
        <span id="loading1"></span>
        <br />
        <small style="color: Red;">* Hình ảnh nhỏ hơn 1mb - Định dạng file jpg, gif, png</small>
        <iframe id="UploadTarget1" name="UploadTarget1" onload="UploadImage_Complete1();" style="position: absolute;left: -999em; top: -999em;"></iframe>
    }
</div>
<div id="dialog2" title="Chỉnh sửa hình ảnh">
    <input id="imageIdEdit" type="hidden" value="" />
    <p><img id="imageEdit" alt="image" width="500px" height="400px" src="" /></p>
    <div class="atributelabel">Sắp xếp</div>
    <div class="atributeeditor"><input type="text" class="input250" name="imageSortEdit" id="imageSortEdit" value=""/></div>
    <div class="clear">&nbsp;</div>
    <div class="atributelabel">Xóa:</div>
    <div class="atributeeditor"><input style="width:auto;" type="checkbox" class="input250" name="imageDelete" id="imageDelete"/></div>
    <div class="clear">&nbsp;</div>
    <div class="atributelabel">&nbsp;</div>
    <div class="atributeeditor">
        <input type="button" value="Lưu" onclick="TourImageUpdate();"/>
    </div>
    <div class="clear">&nbsp;</div>
</div>

<style>
    table
    {
	    border: 1px solid #000;
	    border-collapse: collapse;
	    color: #666666;
	    min-width: 500px;
	    width: 100%;
    }

    tr
    {
	    border: 1px solid #000;
	    line-height: 25px;
    }

    th
    {
	    background-color: #9b9993;
	    color: #FFF;
	    font-size: 13px;
	    text-align: left;
    }

    th, td
    {
        border-left: 1px solid #000;
	    padding-left: 5px;
    }

    tr:hover
    {
	    background-color: #fff;
    }
</style>
@helper Truncate(string input, int length)
{
    if (!string.IsNullOrEmpty(input))
    {
        if (input.Length <= length)
        {
            @input
        }
        else
        {
            @input.Substring(0, length)<text>...</text>
        }
    }
}
<div style="height:10px"></div>

<b><a href="@Url.Action("InsertComment", "AdminHome")">>>>Thêm comment mới<<<</a></b>
<div style="height:10px"></div>
<table>
    <tr>
        <th>Khách hàng</th>
        <th>Nhận xét</th>
        <th>Chỉnh sửa</th>
    </tr>
    @foreach (var item in ViewBag.commnentList as List<DatNuocViet.Models.Comment>)
    {
    <tr>
        <td>@item.Author</td>
        <td>@Truncate(item.CommentContent, 200)</td>
        <td><a href="@Url.Action("EditComment", "AdminHome", new { id = item.CommentId})">Chỉnh sửa</a></td>
    </tr>
    }
</table>